﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Xuat_Nhap_Excel
{
    public partial class FrmLoading : Form
    {
        private bool _mouseDowned;
        private Point _positionMouse;
        public event CancelLoading Cancel;
        public FrmLoading()
        {
            InitializeComponent();
            _mouseDowned = false;
        }
        public void ShowCancel(bool showCancel)
        {
            lblCancel.Visible = showCancel;
        }
        public void Update(string strInfo)
        {
            
        }
        private void MoveWindow_MouseUp(object sender, MouseEventArgs e)
        {
            _mouseDowned = false;
        }

        private void MoveWindow_MouseDown(object sender, MouseEventArgs e)
        {
            _mouseDowned = true;
            _positionMouse = e.Location;
        }

        private void MoveWindow_MouseMove(object sender, MouseEventArgs e)
        {
            MoveForm(e);
        }
        private void MoveForm(MouseEventArgs e)
        {
            if (!_mouseDowned) return;
            int xDiff = _positionMouse.X - e.Location.X;
            int yDiff = _positionMouse.Y - e.Location.Y;
            int x = Location.X - xDiff;
            int y = Location.Y - yDiff;
            Location = new Point(x, y);
        }

        private void lblCancel_Click(object sender, EventArgs e)
        {
            Close();
            lblCancel.Enabled = false;
            if (Cancel != null)
                Cancel(this, new EventArgs());
        }

        private void lblCancel_MouseEnter(object sender, EventArgs e)
        {
            lblCancel.ForeColor = Color.White;
            lblCancel.BackColor = Color.Red;
        }

        private void lblCancel_MouseLeave(object sender, EventArgs e)
        {

        }
    }
    public delegate void CancelLoading(object sender, EventArgs e);
}
